<?php

/** Installation routine
 *  Copies various files to various locations required by functional
 *  Dataxi system. Please use "php install.php" to see the options
 *  available.
 *
 *  This collection of functions (libary) is licensed under GPL2.
 *  See LICENSE or www.gnu.org for more details.
 *
 *  Author: Jyry Kuukkanen
 *
 *  $Id: install.php,v 1.5 2005/03/12 17:06:58 jyry Exp $
 */

$argv = $_SERVER["argv"];
$ostype = $_ENV["OSTYPE"];

/* OS related commands */
switch ($ostype) {
    case "linux":
        $cp = "cp ";
        $cpr = "cp -R";
        $mkdir = "mkdir";
        $chownr = "chown -R";
        break;
    default:
        die("OS not recognised. Sorry. Aboprtin.\n");
}; // switch


/* Check command line parameters */
foreach ($argv as $arg) {
    list($key, $value) = split("=", $arg, 2);
    switch (strtolower($key)) {
        case "lib":
            $lib = $value;
            break;
        case "site":
            $site = $value;
            break;
        case "inc":
            $inc = $value;
            break;
        case "chown":
            $chown = $value;
            break;
    }; // switch
};

/* Print help if no valid paramters are passed */
if (!$lib && !$site && !$chown && !$inc) {
    echo "\nNo, no, no. Not like that. Valid usage:\n\n".
         "install.sh <param1> <param2> ... <param3>\n".
         "where params are key=value pairs.\n\n".
         "Possible keys are:\n".
         "'lib' where to install library files\n".
         "'site' where the application site is located\n".
         "'inc' where to install site include files (absolute path when\n".
         "      'site' not specified, otherwise relative path to 'site'\n".
         "'chown' which users.group right chould be set for site files\n\n".
         "For example:\n".
         "install.sh lib=/usr/lib site=/var/httpd/htdocs ".
         "chown=nobody.nogroup\n";
    die("\n");
};

if ($lib) {
    exec("$mkdir $lib; $cp * $lib; $cpr scripts $lib; $cpr dialogs $lib");
};
if ($site) {
    exec("$mkdir $site; $cp appdir/* $site");
};
if ($inc) {
    if ($site) $site = "/";
    exec("$mkdir $site$inc; $cpr images/* $site$inc");
    exec("$cp styles/* $site$inc");
    exec("$cp scripts/* $site$inc");
};
if ($chown && $chownr) exec("$chownr $chown $site");

?>
